<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Expires", "0");
    %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>网络服务平台</title>
    <link rel="stylesheet" type="text/css" href="/js/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/js/easyui/themes/icon.css">
    <script type="text/javascript" src="/js/easyui/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="/js/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#collectedNewsGrid').datagrid({
                title:'新闻采集源列表',
                iconCls:'icon-save',
                height:460,
                nowrap:false,
                striped:true,
                collapsible:true,
                url:'/management/news/fetchCollectedNews.action',
                queryParams:{"inIndex":"-1", "indexLevel":"-1"},
                remoteSort:false,
                idField:'id',
                frozenColumns:[
                    [
                        {"width":280, "field":"title", "title":"标题"},
                        {"width":180, "field":"source", "title":"来源"}
                    ]
                ],
                columns:[
                    [
                        {"width":380, "field":"sourceLink", "title":"原始链接",
                            formatter:function (value, rowData, rowIndex) {
                                return '<a  target="_blank" href="' + value + ' ">'+ value +'</a>';
                            }
                        },
                        {"width":120, "field":"createDate", "title":"日期"},
                        {"width":80, "field":"id", "title":"操作",
                            formatter:function (value, rowData, rowIndex) {
                                <s:if test="1 == #session._user_role_">
                                return '<a href="/management/news/convertCollectedNews.action?id=' + value + ' ">编辑</a>&nbsp;<a onclick="deleteCollectedNews(\'' + value + '\',\'' + rowIndex + '\');" href="#">删除</a>';
                                </s:if>
                                <s:else>
                                return '<a href="/management/news/convertCollectedNews.action?id=' + value + ' ">编辑</a>';
                                </s:else>

                            }
                        }
                    ]
                ],
                pagination:true,
                rownumbers:true,
                toolbar:[
                    <s:if test="1 == #session._user_role_">
                    {"iconCls":"icon-add", "handler":function () {
                        deleteAllCollectedNews();
                    }, "text":"删除所有采集新闻", "title":"删除所有采集新闻", "id":"btnAdd"}
                    </s:if>
                ]
            });

            $('#indexLevel').combobox('setValue', -1);
            $('#inIndex').combobox('setValue', -1);

            var p = $('#collectedNewsGrid').datagrid('getPager');
            if (p) {
                $(p).pagination({
                    onBeforeRefresh:function () {
                        //	alert('before refresh');
                    }
                });
            }
        });

        function deleteAllCollectedNews(){
            $.messager.confirm('删除所有已采集新闻', '你确定要删除所有已采集新闻吗？', function (data) {
                if (!data) {
                    return;
                }

                $.getJSON("/management/news/deleteAllCollectedNews.action", function (data1) {
                    if (data1.successful) {
                        $.messager.show({
                            title:'提示信息',
                            msg:'删除所有已采集新闻成功！'
                        });
                    } else {
                        $.messager.show({
                            title:'提示信息',
                            msg:'删除所有已采集新闻失败！'
                        });
                    }

                    $('#collectedNewsGrid').datagrid('reload');
                });
            });
        }

        function deleteCollectedNews(id, index) {
            $.messager.confirm('删除已采集新闻', '你确定要删除已采集新闻吗？', function (data) {
                if (!data) {
                    return;
                }

                $.getJSON("/management/news/deleteCollectedNews.action?id=" + id, function (data1) {
                    if (data1.successful) {
                        $.messager.show({
                            title:'提示信息',
                            msg:'删除已采集新闻成功！'
                        });

                        var index = $("#collectedNewsGrid").datagrid('getRowIndex', id);
                        $('#collectedNewsGrid').datagrid('deleteRow', index);
                    } else {
                        $.messager.show({
                            title:'提示信息',
                            msg:'删除已采集新闻失败！'
                        });
                    }
                });
            });
        }

        function query() {
            var collectedNewsTitle = $("#collectedNewsTitle").val();
            var queryParams = $('#collectedNewsGrid').datagrid('options').queryParams;

            queryParams.collectedNewsTitle = collectedNewsTitle;

            $('#collectedNewsGrid').datagrid('options').queryParams = queryParams;
            $("#collectedNewsGrid").datagrid('reload');
        }

        function getSelected() {
            var selected = $("#collectedNewsGrid").datagrid("getSelected");
            return selected;
        }

        function getSelections() {
            var rows = $("#collectedNewsGrid").datagrid("getSelections");
            return rows;
        }

        function selectRow(rowNumber) {
            $("#collectedNewsGrid").datagrid("selectRow", rowNumber);
        }

    </script>

</head>

<body class="easyui-layout">
<s:if test="null == #session._login_user_">
    <script type="text/javascript">
        top.location.href = '/admin';
    </script>
</s:if>
<div region="center" style="height:600px;padding:10px;background:#efefef;">
    <div id="p" class="easyui-panel" title="新闻搜索" icon="icon-search" style="height:80px;padding:10px;">
        <table style="border: #15428B; border-style: solid; border-width: 1px ">
            <tr>
                <td><label>来源:</label></td>
                <td>&nbsp;<input name="collectedNewsTitle" id="collectedNewsTitle"/></td>
                <td><a class="easyui-linkbutton" onclick="query()">搜索</a></td>
            </tr>
        </table>
    </div>
    <div id="p1" class="easyui-panel" style="height:500px;">`
        <table id="collectedNewsGrid"></table>
    </div>
</div>
</body>
</html>